class Enemy
  attr_reader :x, :y, :hp, :speed, :radius, :type, :score, :halfwidth, :halfheight
   #animation = picture file
    #x = x position (starting)
    #y = y position
    #type = tile on .bmp image... this way you can have multiple enemies in one .bmp file
    #hp = hit pionts
    #speed = scroll speed... but eventually this will be changed to speed in whatever direction its going
    #radius = approx radius of object (useful in collision detection and projectile detection)
  def initialize(animation, x, y, type, hp, speed, radius, factorx=1.0, factory=1.0, score=1)
    @animation = animation
    @x = x
    @y = y
    @hp = hp
    #@img = @animation[type]
    @speed = speed
    @radius = radius
    @type = type
    @angle = 0
    @factorx = factorx
    @factory = factory
    @score = score
    @halfwidth = @animation.width/2.0
    @halfheight = @animation.height/2.0
  end
  
  def draw
    @animation.draw_rot(@x , @y , ZOrder::Player,@angle, 0.5, 0.5, @factorx, @factory)
  end
  
  def decrease_hp(value)
    @hp -= value
  end
  
  
  #Updates the x,y coordinates and the @angle of enemy object
  def update
    if @type == 1
      @angle += 0.2
    end
    if @type == 2
      @angle += -0.75
    end
    if @type == 3
      @angle += 1
    end
    if @type == 4
      @angle += -2
    end
    if @type == 5
      @angle += 3
    end
    if @type == 6
      @angle += -0.5
    end
    @y += speed
  end

  def shootAtPlayer(player, projectiles, enemy_projectile)
    angle = (Math::atan2(@y, @x) + Math::atan2(player.y, player.x))
    #if angle < 0
      #angle = angle + 360
    #end
    
    #puts "Angle(Radians): #{angle} Angle(Degrees): #{angle/Math::PI*180}"
    distance = Gosu::distance(@x, @y, player.x, player.y) 
    offsetx = Gosu::offset_x(angle, distance)
    offsety = Gosu::offset_y(angle, distance)
    yspeed = (offsety / offsetx)
    xspeed = (offsetx / offsety)
    #if angle >= 270.0 or angle <= 90.0
      #yspeed = -yspeed
    #end
    #if angle > 180.0
      #xspeed = -xspeed
    #end
    projectiles.push(Projectile.new(enemy_projectile, @x, @y, 1, xspeed, yspeed, angle, false))
  end
end